package com.hernie.piggymall.order.web;

import com.alipay.api.AlipayApiException;
import com.hernie.piggymall.order.config.AlipayTemplate;
import com.hernie.piggymall.order.service.OrderService;
import com.hernie.piggymall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author HuangJp
 * @Date 2022/5/25
 * @Description
 */
@Controller
public class PayWebController {

    @Autowired
    AlipayTemplate alipayTemplate;
    @Autowired
    OrderService orderService;

    /**
     * 将支付页让浏览器展示
     * 支付成功以后，要跳到用户的订单列表页
     * @param orderSn
     * @return
     * @throws AlipayApiException
     */
    @ResponseBody
    @GetMapping(value = "/payOrder", produces = "text/html")    // produces 返回数据类型,如 text/html ， application/json
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
//        PayVo payVo = new PayVo();
//        payVo.setBody();    // 订单的备注
//        payVo.setOut_trade_no();    //订单号
//        payVo.setSubject(); //订单的主题
//        payVo.setTotal_amount();    // 订单的金额

        PayVo payVo = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(payVo); // 返回的是一个页面，将此页面直接交给浏览器即可
        return pay;
    }
}
